-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a missing Plans column on the applications list #3995
Conversation
before_action :find_service | ||
before_action :find_plans |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This order is important for this controller, as when the plans are searched, they are scoped by the service, so the service needs to be pre-filled.
@@ -42,8 +42,8 @@ def find_service | |||
@service = accessible_services.find params[:service_id] | |||
end | |||
|
|||
def accessible_plans | |||
super.where(issuer: @service) | |||
def find_plans |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overriding the find_plans
in order to avoid adding .stock
.
As I understand the logic, the idea is that if there is just one single plan (I guess that's not commonly used, but still), there is no need to show the Plan column, because well, it will always be the same.
But for that purpose I think it is more correct to check all plans (including the custom ones), and not just "stock" plans (non-custom).
/ FIXME: The first condition does not make any sense but application_plans used to be accessible_plans, now it's accessible_plans.stock | ||
/ FIXME 2: application_plans returns [] in services/:id/applications even though there are plans | ||
- show_application_plans = application_plans.size > 0 && !master_on_premises? | ||
- show_application_plans = application_plans.size > 1 && !master_on_premises? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -6,8 +6,8 @@ Feature: Product > Applications | |||
|
|||
Background: | |||
Given a provider | |||
And a product "My API" | |||
And another product "Another API" | |||
And a product "My API" with no plans |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure that the plans created below are the only plans on the respective services.
0276a85
to
79e1076
Compare
@@ -21,7 +21,7 @@ | |||
end | |||
|
|||
# TODO: can we use "has_table?" instead of this complex step? | |||
Then "(I )(they )should see (the )following table(:)" do |expected| | |||
Then /^(?:I )?(?:they )?should see (?:the )?following table( with exact columns)?:?$/ do |exact_columns, expected| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The step was change to avoid touching all the existing scenarios.
I couldn't find a way to add a parameter type within an optional block... In fact, I tried, but cucumber said it was not possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not possible, I've wanted to do the same many times.
However, this is a bit redundant as there is already a way to do this:
Then the table has a column "Plan"
But the table does not have a column "Plan"
If you still want to keep it I would simply suggest:
Then /^(?:I )?(?:they )?should see (?:the )?following table( with exact columns)?:?$/ do |exact_columns, expected| | |
Then /^(?:I |they )?should see (?:the )?following table( with exact columns)?:?$/ do |exact_columns, expected| |
bc527f6
to
9793901
Compare
@@ -40,7 +40,8 @@ | |||
|
|||
retries ||= 1 | |||
|
|||
expected.diff! table | |||
options = exact_columns.present? ? { surplus_col: true } : {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the surplus_col
option, the comparison will fail if the actual table has an extra column that is not defined in the expected table.
| Bob's App | live | Bob | December 11, 2023 | | | ||
When they go to product "My API" applications page | ||
Then they should see the following table with exact columns: | ||
# Plan column is visible because this service has multiple plans |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments tell me that these scenarios have double intent. I suggest we keep them as they were and add a new scenario that tests specifically one thing, the Plans column:
Scenario: Plan column is visible when service has multiple plans
Scenario: Plan column is not visible when service has just one plan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the intention is to verify that the table is rendered exactly as expected.
If the presence of the column Plans depends on some conditions, this is taken into account. I didn't know about the the table has a column
step, and well, it seems useful, but I think verifying not only that the column is present (I guess it checks the header), but also that each row has a correct value for that column is important.
I can remove those comment lines 😬 And then this verification would be kind of implicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a matter of not mixing concerns. Let me elaborate.
The scenario reads "Only the current service applications are listed", it meets specific conditions and performs specific assertions. There are 2 products, each own with plans, and I want to make sure that the index page doesn't mix up both.
This PR implements (or rather fixes) a completely different piece of logic: that depending on the number of plans (regardless of the current service), there will be an extra column.
Testing that "the table renders exactly as expected" as you put it isn't ideal because nobody will now what "as expected" means. It may be clear now in this PR, but anybody looking at it without context will get confused. If this test ever fails, it will require some degree of debugging and investigation to figure out that column Plan's visibility changes.
This should be made explicit by the scenario's title, background and steps.
This of course also applies to the next scenario: "Paid? column is shown when finance is enabled". There is a whole scenario to test column "Paid?", why not for "Plans"?
Say someone adds a new plan to "Another API", for whatever reason. Then Paid? column is shown when finance is enabled
and Only the current service applications are listed
will both fail, even though they should not, because "Another API" having 2 plans doesn't affect either the column "Paid?" or "API"'s applications table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't disagree with anything you say, but I am not sure what is the best way to "make this right".
Testing that "the table renders exactly as expected" as you put it isn't ideal because nobody will now what "as expected" means.
Well, in this case "as expected" means - exactly like the table in the step. I was actually surprised that the the expected table didn't need to be complete - I think this is quite error-prone. An accidental change may result in some columns disappearing, and we'll never catch it.
it will require some degree of debugging and investigation to figure out that column Plan's visibility changes.
That was the reason why I added those comments, although I agree, this is not ideal, and the scenario/steps descriptions should be enough to explain what the test is verifying.
This of course also applies to the next scenario: "Paid? column is shown when finance is enabled". There is a whole scenario to test column "Paid?", why not for "Plans"?
This is also not ideal, because this pretty much copies the previous scenario, but just adds the "Paid?" column. And this is the reason why it has to be a separate scenario - because it can't be tested together with the previous one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josemigallas I've updated the scenarios here: 6b718f7
9793901
to
d5c1e11
Compare
bee4d4d
to
6b718f7
Compare
What this PR does / why we need it:
Fixes the missing Plan column on the application listing.
Before:
![Screenshot from 2025-01-28 15-35-24](https://private-user-images.githubusercontent.com/1270328/407357906-93e7e0fd-5688-43f0-8864-d5df62153abf.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5NTE1NzksIm5iZiI6MTczODk1MTI3OSwicGF0aCI6Ii8xMjcwMzI4LzQwNzM1NzkwNi05M2U3ZTBmZC01Njg4LTQzZjAtODg2NC1kNWRmNjIxNTNhYmYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDdUMTgwMTE5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NDUwNjBhZDI5ZmI2Mzk5ODI2OTZiNDU2NDMyZDg2MjYwNjg0YzEwODhjNGVkN2M2Njc4MDY2MDc5ZjEwNzlmNiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.MVAPvVKFhzLQES4ubBwBTq_QVtSo5hnNLtcmGODgF7Y)
After:
![Screenshot from 2025-01-28 15-35-39](https://private-user-images.githubusercontent.com/1270328/407357932-449f7fc3-f08d-4278-ac4f-a267ee1e136a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5NTE1NzksIm5iZiI6MTczODk1MTI3OSwicGF0aCI6Ii8xMjcwMzI4LzQwNzM1NzkzMi00NDlmN2ZjMy1mMDhkLTQyNzgtYWM0Zi1hMjY3ZWUxZTEzNmEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDdUMTgwMTE5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTZkOGMwMjYyMDg1OTI0NWJkMDlkNzdlODhjMTI2NDFiZTFkODk1Mjc0ZTk5ZjA0ZjUzZTIwMDRjNzgwYjAxYyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.MG1bwXdRbA3bXjLr_sma8JHz6xSv999c2gkYICef1GU)
Which issue(s) this PR fixes
not registered
Verification steps
View a list of applications under a service that has multiple plans, and make sure that there is a Plans column.
Special notes for your reviewer:
See comments inline